Skip to content

Python codegen: docstrings and attribute-access ENV for hover docs - #1219

Merged
theoephraim merged 2 commits into
mainfrom
python-codegen-docstrings-attrs
Oct 13, 2026
Merged

theoephraim merged 2 commits into
mainfrom
python-codegen-docstrings-attrs

Conversation

@theoephraim

Copy link
Copy Markdown
Member

Closes #1215.

@generatePythonEnv output now shows item docs in the editor where values are read.

  • New EnvAttrs class with one documented, typed @property per item, plus a lazily loaded module-level ENV (from env import ENV; ENV.DB_PORT). Loads on first access and is cached, so importing the module stays side-effect-free. The module __getattr__ is hidden from type checkers so typo'd imports still error.
  • Env TypedDict fields get attribute docstrings instead of # comments (description, @docs() as Markdown links, deprecation, valid values, sensitivity). Quotes and backslashes are escaped.
  • @deprecated items get typing_extensions.deprecated on the property (type-checker-only import, runtime no-op), so checkers flag reads and editors strike them through.
  • NotRequired now comes from typing_extensions, fixing pyright errors on the generated file when targeting Python < 3.11.
  • load_env() and the Env dict are unchanged.

Verified with the pyright language server (hover + go-to-definition on ENV.KEY), pyright strict and mypy strict on 3.8/3.9 and 3.13, and a runtime import on Python 3.9.

Not included: the issue's proposed Source: line (the TS output doesn't have it either; it needs item source paths plumbed into the generators).

@generatePythonEnv now emits an EnvAttrs class with a documented property per
item and a lazily loaded module-level ENV, so Pyright/Pylance show item docs on
hover where values are read. Env TypedDict fields get attribute docstrings
instead of # comments, deprecated items map to typing_extensions.deprecated,
and NotRequired comes from typing_extensions so checkers targeting < 3.11 work.

Closes #1215
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

bumpy-frog

The changes in this PR will be included in the next version bump.

minor Minor releases

  • @varlock/native-helper-darwin 1.22.0 → 1.23.0
  • @varlock/native-helper-linux-arm64 1.22.0 → 1.23.0
  • @varlock/native-helper-linux-x64 1.22.0 → 1.23.0
  • @varlock/native-helper-win32-x64 1.22.0 → 1.23.0
  • varlock 1.22.0 → 1.23.0

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle size

⚠️ grows the bundle by 11.7 KB (+0.2%)

Metric main This PR Δ
Total dist 5029.0 KB 5040.7 KB +11.7 KB (+0.2%)
JS 1904.2 KB 1908.6 KB +4.3 KB (+0.2%)
Sourcemaps 2994.6 KB 3002.0 KB +7.4 KB (+0.2%)
Type defs 130.2 KB 130.2 KB —
Other 0.0 KB 0.0 KB —

dist/ only; native binaries are versioned separately and not counted here.

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@1219

@varlock/native-helper-darwin

npm i https://pkg.pr.new/@varlock/native-helper-darwin@1219

@varlock/native-helper-linux-arm64

npm i https://pkg.pr.new/@varlock/native-helper-linux-arm64@1219

@varlock/native-helper-linux-x64

npm i https://pkg.pr.new/@varlock/native-helper-linux-x64@1219

@varlock/native-helper-win32-x64

npm i https://pkg.pr.new/@varlock/native-helper-win32-x64@1219

commit: 8d337a7

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Valid env keys can make the new attribute-access module fail mypy checking because properties shadow type names used in later annotations.

Reviewed changes Reviewed the Python generator, shared documentation sanitization, tests, and user documentation.

  • Attribute access: Adds documented EnvAttrs properties and a lazily loaded, cached module-level ENV, while retaining load_env() dict access.
  • Editor documentation: Emits escaped field and property docstrings, Markdown documentation links, sensitivity information, and type-checker deprecation markers.
  • Compatibility and coverage: Moves NotRequired to type-only typing_extensions imports, filters reserved property names, and updates tests and Python usage guides.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

A property named after a type the class body references (str, int, Env, ...)
shadows it for later annotations, which mypy rejects.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the reserved-name fix since the prior review at 2124f16f.

  • Expanded collision filtering: Omitted type-name keys from EnvAttrs while retaining them in the Env dict, preventing mypy errors in later property annotations.
  • Strengthened regression coverage: Added colliding names before an optional getter; all eight emitter tests and an independent generated-module probe passed mypy strict and Python runtime checks.
  • Updated documentation: Listed the additional reserved attribute names and explained the load_env() fallback.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website 8d337a7 Commit Preview URL

Branch Preview URL
Oct 13 2026, 09:15 PM

@theoephraim
theoephraim merged commit 8bcdd86 into main Oct 13, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Python codegen: docstrings and attribute access so item docs show on hover

1 participant